package nc.tb.report.plugin;

import java.awt.Component;

import nc.tb.analyse.pub.QueryPlan;
import nc.tb.app.CommonPlan;
import nc.tb.app.version.ui.MutiRowCellRenderer;
import nc.tb.cube.cell.MutiRowCellValueObject;
import nc.tb.cube.model.MetaPlan;
import nc.tb.cube.model.Plan;
import nc.tb.ufo.ui.IMode;

import com.ufsoft.report.UfoReport;
import com.ufsoft.report.plugin.AbsActionExt;

public abstract class TbActionExt extends AbsActionExt {
	protected UfoReport m_report;
//	public TbActionExt() {
//	}
//	public TbActionExt(UfoReport rep) {
//		this.m_report=rep;
//	}
	
	protected boolean isVersionStatus() {
		if (m_report != null && m_report instanceof TbReport) {
			return ((TbReport)m_report).getMode() == IMode.VERSION || ((TbReport)m_report).getMode() == IMode.ADJUSTQUERY;
		}
		else
			return false;
//		boolean isVersionContract = false;
//		try {
//			isVersionContract = m_report.getTable().getReanderAndEditor().getRender(MutiRowCellValueObject.class) instanceof MutiRowCellRenderer;
//		} catch (Exception e) {
//		}
//		return isVersionContract;
	}
	public boolean isEnabled(Component focusComp) {
//		boolean isVersionContract = false;
//		try {
//			isVersionContract = m_report.getTable().getReanderAndEditor().getRender(MutiRowCellValueObject.class) instanceof MutiRowCellRenderer;
//		} catch (Exception e) {
//		}
//		if (isVersionContract)
//			return false;
		if (isVersionStatus())
			return false;
		try {
			Plan plan = ((TbReport)m_report).getViewUIModel().getPlan();
			if (plan instanceof MetaPlan && !isEnabledInCube())
				return false;
			if (plan instanceof CommonPlan && !isEnabledInPlan())
				return false;
			if (plan instanceof QueryPlan && !isEnabledInQuery())
				return false;
		} catch (Exception e) {
		}
		return true;
	}
	
	protected boolean isEnabledInCube() {
		return true;
	}
	
	protected boolean isEnabledInPlan() {
		return true;
	}
	
	protected boolean isEnabledInQuery() {
		return true;
	}

}
